package com.jdjw.modules.thirdpost.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jdjw.modules.thirdpost.entity.ThirdPostExceptionLog;
import com.jdjw.modules.thirdpost.mapper.ThirdPostExceptionMapper;
import com.jdjw.modules.thirdpost.param.PageList;
import com.jdjw.modules.thirdpost.param.ThirdExceptionParam;
import com.jdjw.modules.thirdpost.param.ThirdPostInParm;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 31张省表发送数据异常表 服务实现类
 * </p>
 *
 * @author fq
 * @since 2021-08-13
 */
@Service
public class ThirdPostExceptionServiceImpl extends ServiceImpl<ThirdPostExceptionMapper, ThirdPostExceptionLog> implements ThirdPostExceptionService {

    @Autowired
    ThirdPostExceptionService thirdPostExceptionService;

    @Autowired
    StaEconomicCooperativeImpl staEconomicCooperativeImpl;

    @Autowired
    ProjectServiceImpl projectServiceImpl;

    @Autowired
    ProjectPayPersonnelServiceImpl projectPayPersonnelServiceImpl;

    @Autowired
    OfficialSealImpl officialSealImpl;

    @Autowired
    MigrantSettlementServiceImpl migrantSettlementServiceImpl;

    @Autowired
    LaborEmploymentServiceImpl laborEmploymentServiceImpl;

    @Autowired
    HonestStraightToImpl honestStraightToImpl;

    @Autowired
    HonestOpinionsImpl honestOpinionsImpl;

    @Autowired
    BusAssetApplyParamServiceImpl busAssetApplyParamServiceImpl;

    @Autowired
    SzZyxzcmxbJiandeServiceImpl szZyxzcmxbJiandeServiceImpl;

    @Autowired
    BusProcureApplyServiceImpl busProcureApplyServiceImpl;

    @Autowired
    BusProcureApplyJudgeServiceImpl busProcureApplyJudgeServiceImpl;

    @Autowired
    BusAssetApplyTouBiaoSetviceImpl busAssetApplyTouBiaoSetviceImpl;

    @Autowired
    BusWarningResultServiceImpl busWarningResultServiceImpl;

    @Autowired
    BusComplainttwoServiceImpl busComplainttwoServiceImpl;

    /**
     * 插入异常数据
     *
     * @param methodName 方法名
     * @param tableName  表名
     * @param returnData 返回数据
     * @param postTime   发送时间
     */
    @Override
    public void insertExceptionData(String methodName, String tableName, String returnData, String postTime) {
        ThirdPostExceptionLog tpe = new ThirdPostExceptionLog();
        tpe.setMethodName(methodName);
        tpe.setTableName(tableName);
        tpe.setReturnData(returnData);
        tpe.setPostTime(postTime);
        tpe.setState(0);
        this.save(tpe);
    }

    @Override
    public IPage<ThirdPostExceptionLog> list(PageList queryEntity) {
        QueryWrapper<ThirdPostExceptionLog> wrapper = new QueryWrapper();
        if (StringUtils.isNotEmpty(queryEntity.getState())) {
            wrapper.eq("state", queryEntity.getState());
        }
        Page<ThirdPostExceptionLog> tpePage = new Page<>(queryEntity.getPage(), queryEntity.getLimit());
        IPage<ThirdPostExceptionLog> page = thirdPostExceptionService.page(tpePage, wrapper);
        return page;
    }

    @Override
    public String retry(ThirdExceptionParam thirdExceptionParam) {
        ThirdPostInParm tp = new ThirdPostInParm();
        tp.setStartTime(thirdExceptionParam.getPostTime());
        tp.setEndTime(thirdExceptionParam.getPostTime());
        tp.setMethodType("2");
        switch (thirdExceptionParam.getMethodName()) {
            case "doPostProject":
                projectServiceImpl.doPostProject(tp);//1
            case "doPostProjectContract":
                projectServiceImpl.doPostProjectContract(tp);//3
            case "doPostProjectTender":
                projectServiceImpl.doPostProjectTender(tp);//4
            case "doPostCompany":
                projectPayPersonnelServiceImpl.doPostCompany(tp);//5
            case "doPostPersonnel":
                projectPayPersonnelServiceImpl.doPostPersonnel(tp);//6
            case "doPostPay":
                projectPayPersonnelServiceImpl.doPostPay(tp);//7
            case "doPostSzZyxzcmxbJiande":
                szZyxzcmxbJiandeServiceImpl.doPostSzZyxzcmxbJiande(tp);//8
            case "doPostCzxx":
                busAssetApplyParamServiceImpl.doPostCzxx(tp);//9
            case "doPostYs2":
                busAssetApplyParamServiceImpl.doPostYs2(tp);//10
            case "doPostSs1":
                busAssetApplyParamServiceImpl.doPostSs1(tp);//11
            case "doPostSs2":
                busAssetApplyParamServiceImpl.doPostSs2(tp);//12
            case "doPostLaborEmployment":
                laborEmploymentServiceImpl.doPostLaborEmployment(tp);//13
            case "doPostMigrantSettlement":
                migrantSettlementServiceImpl.doPostMigrantSettlement(tp);//14
            case "doPostSZyxzcmxbJiande":
                busProcureApplyServiceImpl.doPostSZyxzcmxbJiande(tp);//15
            case "BusZhifu":
                busProcureApplyServiceImpl.BusZhifu(tp);//16
            case "doPostBusProcureZishiqi":
                busProcureApplyJudgeServiceImpl.doPostBusProcureZishiqi(tp);//17
            case "BusCaigouhetong":
                busProcureApplyServiceImpl.BusCaigouhetong(tp);//18
            case "BusCaigouleibie":
                busProcureApplyServiceImpl.BusCaigouleibie(tp);//19
            case "doPostSzJiandeershi":
                busAssetApplyTouBiaoSetviceImpl.doPostSzJiandeershi(tp);//20
            case "doPostSzZyxzWangShang":
                busWarningResultServiceImpl.doPostSzZyxzWangShang(tp);//21
            case "doPostBusProcureBanLi":
                busComplainttwoServiceImpl.doPostBusProcureBanLi(tp);//22
            case "doPostSzJiandeersan":
                busWarningResultServiceImpl.doPostSzJiandeersan(tp);//23
            case "doPostofficialseal":
                officialSealImpl.doPostofficialseal(tp);//24
            case "doPoststaEconomicCooperative":
                staEconomicCooperativeImpl.doPoststaEconomicCooperative(tp);//25 ？
            case "doPosthonestOpinions":
                honestOpinionsImpl.doPosthonestOpinions(tp);//26
            case "doPosthonestStraightTo":
                honestStraightToImpl.doPosthonestStraightTo(tp);//27
            case "doPostBusProcureApplyZi":
                busComplainttwoServiceImpl.doPostBusProcureApplyZi(tp);//28
            case "doPostBusProcureErJiu":
                busComplainttwoServiceImpl.doPostBusProcureErJiu(tp);//29
            case "doPostYs1":
                busAssetApplyParamServiceImpl.doPostYs1(tp);//30
            case "doPostProjectCost":
                projectServiceImpl.doPostProjectCost(tp);//31
            default:;
        }
        return "成功";
    }

}
